package org.dandelion.memo.entity;

import android.util.Log;

import androidx.annotation.NonNull;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Memo implements Serializable {
    private int id = 1;
    private String title;
    private String content;
    private LocalDateTime dateTime;
    private boolean isFavourite;
    private boolean isDeleted;
    private MemoCategory category; // 外键
    private static final DateTimeFormatter dateTimeFormatter =
            DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");

    public Memo() {
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public LocalDateTime getDateTime() {
        return dateTime;
    }

    public void setDateTime(LocalDateTime dateTime) {
        this.dateTime = dateTime;
    }

    public void setDateTime(String dateTimeString) {
        Log.e("MemoDate", dateTimeString);

        dateTime = dateTimeString == null ? null :
                LocalDateTime.parse(dateTimeString, dateTimeFormatter);
    }

    public String getDateTimeAsString() {
        return dateTime == null ? null : dateTime.format(dateTimeFormatter);
    }

    public boolean isFavourite() {
        return isFavourite;
    }

    public void setFavourite(boolean favourite) {
        isFavourite = favourite;
    }

    public boolean isDeleted() {
        return isDeleted;
    }

    public void setDeleted(boolean deleted) {
        isDeleted = deleted;
    }

    public MemoCategory getCategory() {
        return category;
    }

    public void setCategory(MemoCategory category) {
        this.category = category;
    }

    @Override
    @NonNull
    public String toString() {
        return "Memo{" +
                "id=" + id +
                ", title='" + title + '\'' +
                ", content='" + content + '\'' +
                ", dateTime=" + dateTime +
                ", isFavourite=" + isFavourite +
                ", isDeleted=" + isDeleted +
                ", category=" + category +
                '}';
    }
}
